import sys
import redis
import json
import pandas as pd

def DRL(network_path, target_constraint_path, attack_target_path, oscillation_time, source):
    # 原始数据结构（不能修改）
    attack_target = {
        '时间': ['1-20', '5-25', '24-39'],
        '目标节点': ['3,5,90', '33,44', '5,90']
    }

    # 构造 Redis 要发送的数据(假设是PY的)
    valueGd = [
        {"time": t, "value": n}
        for t, n in zip(attack_target['时间'], attack_target['目标节点'])
    ]
    # 构造 Redis 要发送的数据(假设是XJ的)
    valueXj = [
        {"time": t, "value": n}
        for t, n in zip(attack_target['时间'], attack_target['目标节点'])
    ]

    # 写入 CSV 文件（保持原结构）
    df_attack_target = pd.DataFrame(attack_target)
    df_attack_target.to_csv(attack_target_path, index=False)

    # 连接 Redis by VainTale--statrt--
    r = redis.Redis(
        host='43.136.88.28',
        port=6379,
        db=4,
        password='147258369',
        decode_responses=True
    )
    r.xadd("redis-stream-02",{
        "source": source,
        "valueGd": json.dumps(valueGd, ensure_ascii=False),
        "valueXj": json.dumps(valueXj, ensure_ascii=False)
    })


if __name__ == "__main__":
    network_path = sys.argv[1]
    target_constraint_path = sys.argv[2]
    attack_target_path = sys.argv[3]
    oscillation_time = float(sys.argv[4])
    source = sys.argv[5]

    DRL(network_path, target_constraint_path, attack_target_path, oscillation_time, source)
